package zhong.mp3player;

import java.util.List;

import zhong.model.Mp3Info;
import zhong.utils.FileUtils;
import android.R;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class LocalMp3ListActivity extends ListActivity{
	
	List<Mp3Info> mp3Infos;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(zhong.mp3player.R.layout.local_mp3_list);
	}
	

	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		
		FileUtils fileUtils=new FileUtils();
		mp3Infos=fileUtils.getLocalMp3Files("mp3");
		SimpleAdapter simpleAdapter=fileUtils.buildSimpleAdapter(mp3Infos, this);
		setListAdapter(simpleAdapter);
		
	}


	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		// TODO Auto-generated method stub
		super.onListItemClick(l, v, position, id);
		if(mp3Infos!=null){
			Mp3Info mp3Info=mp3Infos.get(position);
			Intent intent=new Intent();
			intent.putExtra("mp3Info", mp3Info);
			intent.setClass(this, PlayerActivity.class);
			this.startActivity(intent);
			
		}
	}
	
	
	
	

}
